package design.patttern.singleton.lazy;

/** 雙重檢查枷鎖，在getInstance()中減少使用同步
 * Created by SliverZhang on 2018/1/15.
 */
public class Singleton1 {
    //  volatile
    private volatile static Singleton1 uniqueSingleton1;

    private Singleton1(){

    }
    /*

     */
    public static Singleton1 getUniqueSingleton1(){
       if (uniqueSingleton1 == null)
       synchronized (Singleton1.class){
           if (uniqueSingleton1 == null){
               uniqueSingleton1 = new Singleton1();
           }
       }
       return uniqueSingleton1;
    }
}
